package com.itheima.注解.自定义注解;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Author 王加鑫
 * @Date 2021/5/29 10:29
 * @Version 1.0
 */
public class MyClassTest {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        Class<MyClass> aClass = MyClass.class;
        MyClass myClass = aClass.newInstance();
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            try {
                if(method.isAnnotationPresent(Test.class)){
                    method.invoke(myClass);
                    System.out.println(method.getName() + "没有异常,运行成功");
                }
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }

    }
}
